package io.sage.modules.basics.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import io.sage.modules.sys.dao.SysUserMapper;
import io.sage.modules.sys.entity.SysUserEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import io.sage.modules.basics.dao.BWarehouseMapper;
import io.sage.modules.basics.entity.BWarehouse;
import io.sage.modules.basics.service.BWarehouseService;
import org.springframework.transaction.annotation.Transactional;

@Service("warehouseService")
public class BWarehouseServiceImpl implements BWarehouseService {

	@Autowired
	private BWarehouseMapper warehouseMapper;

	@Autowired
	private SysUserMapper sysUserMapper;
	@Override
	public List<BWarehouse> selectWarehouseList(Map<String, Object> params) {

		return warehouseMapper.selectWarehouseList(params);
	}

	@Override
	public BWarehouse selectByPrimaryKey(Integer id) {

		return warehouseMapper.selectByPrimaryKey(id);
	}
	@Override
	@Transactional
	public int insert(BWarehouse warehouse) {
		try{
			warehouse.setCreateTime(new Date());
			warehouse.setUpdateTime(new Date());
			warehouse.setIsDel(0);
			warehouse.setIsUsed(1);
			int i=warehouseMapper.insertSelective(warehouse);
			if(i>0){
				i=warehouseMapper.updateCodeByPrimaryKey(warehouse);
			}
			return i;
		}catch (Exception e){
			e.printStackTrace();
		}
		return 0;
	}

	@Override
	public int updateByPrimaryKeySelective(BWarehouse warehouse) {
		warehouse.setUpdateTime(new Date());
		return warehouseMapper.updateByPrimaryKeySelective(warehouse);
	}

	@Override
	public int deleteBatchIds(Integer[] ids) {
		// TODO Auto-generated method stub
		return warehouseMapper.deleteBatchIds(ids);
	}

	@Override
	public List<BWarehouse> selectIsUse(Integer[] ids) {

		return warehouseMapper.selectIsUse(ids);
	}

	@Override
	public Boolean getIsCheck(Integer id) {
		Integer isCheck=this.warehouseMapper.getIsCheck(id);

		return isCheck==1?true:false;
	}

	@Override
	public List<Map<String, Object>> selectAntennaByLikeDeptNo(String deptNoId) {
		return warehouseMapper.selectAntennaByLikeDeptNo(deptNoId);
	}

	@Override
	public List<BWarehouse> selectByGoodsIds(List<Integer> ecceptionBGoodsList) {
		List<BWarehouse> list=warehouseMapper.selectByGoodsIds(ecceptionBGoodsList);
		for (int i = 0; i < list.size(); i++) {
			List<SysUserEntity>userEntityList=sysUserMapper.queryByWarehouseId(list.get(i).getId());
		}
		return list;
	}
}
